package com.server.pojo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.server.pojo.base.PojoBase;
import lombok.*;
import lombok.experimental.Accessors;
import org.hibernate.Hibernate;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

@Getter
@Setter
@ToString

@Entity
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@Table
public class Notice extends PojoBase {
    String title;
    String body;
    String fileUrls;

    @JsonIgnore
    @ToString.Exclude
    @OneToMany(mappedBy = "notice",cascade = CascadeType.ALL)
    List<MobileAppNotice> mobileAppNotices = new ArrayList<>();

    public List<String> getFileUrls() {
        return Arrays.asList(fileUrls.split(","));

    }

    public void setFileUrls(List<String> fileUrls) {
        this.fileUrls = String.join(",",fileUrls);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
        Unit unit = (Unit) o;
        return getId() != null && Objects.equals(getId(), unit.getId());
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}
